import request from '@/libs/request';
let _self;
export const index =  {
	props: {
		show: {type: Boolean,default: false},
		title: {type: String,default: ""},
		optData:{type: Object,default: {}},
	},
	data() {
		return {
			host:process.env.HOST,
			showBox:false,
			boxTitle:this.title,
			showConfirm:false,
			formData:{},
			workerList:[],
			workerIndex:0,
			rules:{
				material_nums: {
					rules: [
						{required: true,errorMessage: '请输入宽度'},
						{pattern: "^(\\-|\\+)?\\d+(\\.\\d+)?",errorMessage: '请输入数字'}
					]
				},
				material_cost: {
					rules: [
						{required: true,errorMessage: '请输入长度'},
						{pattern: "^(\\-|\\+)?\\d+(\\.\\d+)?",errorMessage: '请输入数字'}
					]
				},
			}			
		}
	},
	
	
	watch:{
		show(val){
			this.showBox=val;
			if(val){
				this.initData();
			}
		},

		showBox(val){this.$emit('update:show', val);},
		title(val){this.boxTitle=val;},

	},
	created() {
		_self = this;
	},

	methods: {
		async initData(){
			let retInfo= await request({url: '/api/worker/dataList',method: 'POST',data:{"pageSize":999}});
			this.workerList=retInfo["dataList"];
		},
		cancel(e){this.showBox=false;},
		confirmBox(e){
			this.$refs.form.validate().then(res=>{
				this.showConfirm=true;
				
			}).catch(err =>{
				_self.optLock=false;
				console.log('表单错误信息：', err);
			})
		},
		submitForm(){},
		confirmForm: async function() {	
			this.formData["worker"]=this.workerList[this.workerIndex]["name"];
			var postData=Object.assign({"id":this.optData.id},this.formData);
			let ret= await request({url: '/api/order/updataInfo',method: 'POST',data:postData});
			if(ret=="success"){
				this.optData["material_nums"]=this.formData["material_nums"];
				this.optData["material_cost"]=this.formData["material_cost"];
				this.optData["worker"]=this.formData["worker"];
				let optInfo=Object.assign({"confirm":true},this.optData);
				this.showBox=false;this.showConfirm=false;
				this.$emit('update:optData',{});
				this.$emit('update:optData',optInfo);
			}

		},

		selectChange(){
			this.workerIndex=e.detail.value;
		}

	}
}